﻿using RpcExtend.Collect;
using RpcExtend.Collect.Model;
using RpcExtend.Model;
using RpcHelper;
using RpcModel;
using RpcModularModel.Shield;
using RpcModularModel.Shield.Model;

namespace RpcExtend.Service.Event
{
    /// <summary>
    /// 资源屏蔽接口
    /// </summary>
    internal class ResourceShieIdEvent : RpcClient.Interface.IRpcApiService
    {
        private IResourceShieldCollect _ResourceShield;

        public ResourceShieIdEvent(IResourceShieldCollect resourceShield)
        {
            this._ResourceShield = resourceShield;
        }

        public void SyncShieId(SyncShieId obj)
        {
            this._ResourceShield.Refresh(obj.Path, new ShieIdQuery
            {
                RpcMerId = obj.RpcMerId,
                ServerId = obj.ServerId,
                SystemType = obj.SystemType,
                VerNum = obj.VerNum
            });
        }


        public ShieldDatum CheckIsShieId(CheckIsShieId obj, MsgSource source)
        {
            ResourceShield shield = this._ResourceShield.GetShield(new ShieIdQuery
            {
                RpcMerId = source.RpcMerId,
                ServerId = source.ServerId,
                SystemType = source.SystemType,
                VerNum = source.ApiVer
            }, obj.Path);
            if (shield.Id == 0 || shield.BeOverdueTime <= DateTime.Now.ToLong())
            {
                return new ShieldDatum();
            }
            return new ShieldDatum
            {
                IsShieId = true,
                OverTime = shield.BeOverdueTime
            };

        }
    }
}
